package com.liyiruo.dwb.service;

import com.liyiruo.dwb.domain.Ebook;
import com.liyiruo.dwb.domain.EbookExample;
import com.liyiruo.dwb.mapper.EbookMapper;
import com.liyiruo.dwb.req.EbookReq;
import com.liyiruo.dwb.resp.EbookResp;
import com.liyiruo.dwb.util.CopyUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author liyiruo
 * @Description
 * @Date 2021/12/4 下午12:05
 */
@Service
public class EbookService {
    @Resource
    EbookMapper ebookMapper;

    public List<EbookResp> list(EbookReq req) {
        EbookExample ebookExample = new EbookExample();
        EbookExample.Criteria exampleCriteria = ebookExample.createCriteria();
        exampleCriteria.andNameLike("%" + req.getName() + "%");
        List<Ebook> ebookList = ebookMapper.selectByExample(ebookExample);
        List<EbookResp> list = new ArrayList<>();
        ebookList.forEach(ebook -> {
            EbookResp ebookResp = new EbookResp();
            ebookResp.setId(ebook.getId());
            ebookResp.setName(ebook.getName());
            list.add(ebookResp);
        });
        //调用方法复制list
        //List<EbookResp> ebookRespList = CopyUtil.copyList(ebookList, EbookResp.class);
        return list;
    }


}
